package com.wpl.controller;

import com.wpl.bean.User;
import com.wpl.common.WebResponse;
import com.wpl.service.IServingService;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 是否服务模块
 */
@RestController
@RequestMapping("/serving/")
public class ServingController {

    @Resource
    private IServingService servingService;

    /**
     * 改变User服务状态
     * @param request
     * @return
     */
    @PostMapping("/onServing")
    public WebResponse onServing(HttpServletRequest request,Integer serving){
        User user = (User) SecurityUtils.getSubject().getSession().getAttribute("user");
        user.setServing(serving);
        int count = servingService.changeServing(user, user.getUsername());
        if(count>0){
            return WebResponse.success(count);
        }else {
            return WebResponse.failed();
        }
    }

}
